package com.atguigu.linklist;
class Node{
    public int val;
    public Node next;
    public Node(int val){
        this.val=val;
    }
}
public class TheCommonPartOfTwoList {
    public static void printTheCommonPart(Node head1,Node head2){
        if(head1==null || head2== null) return;
        while(head1!=null && head2!=null){
            if(head1.val==head2.val){
                System.out.print(head1.val+" ");
            }else if(head1.val<head2.val){
                head1=head1.next;
            }else{
                head2=head2.next;
            }
        }
    }
}
